﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.HVAC;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYCreateDuct.MethodCreateDuct;
using HYCreateDuct.MethodHelp;

namespace HYCreateDuct.FormDuct
{
	public partial class FormDuctSet : HYBaseForm
	{
		public FormDuctSet(UIApplication m_uiApp, int Inner, int SelectType, DuctHisHelp hisHelp)
		{
			this.InitializeComponent();
			this.uiApp = m_uiApp;
			this.doc = this.uiApp.ActiveUIDocument.Document;
			this.btnAdd.Image = Resource.GetImage("AddNew16");
			this.btnDelete.Image = Resource.GetImage("delete16");
			this.btnAddCL.Image = Resource.GetImage("AddNew16");
			this.btnDeleteCL.Image = Resource.GetImage("delete16");
			this.btnAddColor.Image = Resource.GetImage("AddNew16");
			this.btnDeleteColor.Image = Resource.GetImage("delete16");
			this.cbMedia.SelectedIndex = 0;
			this.nInner = Inner;
			this.nTypeSelect = SelectType;
			this.hisHelp = hisHelp;
		}

		public FormDuctSet(Autodesk.Revit.DB.Document m_doc)
		{
			this.InitializeComponent();
			this.doc = m_doc;
			this.btnAdd.Image = Resource.GetImage("AddNew16");
			this.btnDelete.Image = Resource.GetImage("delete16");
			this.btnAddCL.Image = Resource.GetImage("AddNew16");
			this.btnDeleteCL.Image = Resource.GetImage("delete16");
			this.btnAddColor.Image = Resource.GetImage("AddNew16");
			this.btnDeleteColor.Image = Resource.GetImage("delete16");
			this.cbMedia.SelectedIndex = 0;
		}

		private void InitCbType()
		{
			XmlHelp xmlHelp = new XmlHelp();
			this.lstDU = xmlHelp.ReadSystemSet("");
			foreach (DuctSystemList ductSystemList in this.lstDU)
			{
				this.cbType.Items.Add(ductSystemList.strTypeName);
			}
			if (this.lstDU.Count > 0)
			{
				this.cbType.SelectedIndex = 0;
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
			base.Close();
		}

		private void rbRect_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbRect.Checked)
			{
				DataTable dataSource = this.BindDataGrid(1);
				this.dvDuctSize.DataSource = null;
				this.dvDuctSize.DataSource = dataSource;
				this.lstRectSize = this.GetDataViewSize();
			}
		}

		private void rbCurve_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbCurve.Checked)
			{
				DataTable dataSource = this.BindDataGrid(2);
				this.dvDuctSize.DataSource = null;
				this.dvDuctSize.DataSource = dataSource;
				this.lstCriSize = this.GetDataViewSize();
			}
		}

		private void btnCreateModel_Click(object sender, EventArgs e)
		{
			FormNewModel formNewModel = new FormNewModel();
			if (formNewModel.ShowDialog() == DialogResult.OK)
			{
				string strNewName = formNewModel.strNewName;
				IEnumerator enumerator = this.cbType.Items.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current.Equals(strNewName))
						{
							YJKMessageBox.Show("您选择的内置系统与当前项目中系统名称冲\n\r突,将替换为内置系统中设置。");
							return;
						}
					}
				}
				int selectedIndex = this.cbType.SelectedIndex;
				new DuctSystemList();
				this.lstDU.Add(this.lstDU[selectedIndex]);
				this.cbType.Items.Add(strNewName);
				this.cbType.SelectedIndex = this.lstDU.Count - 1;
			}
		}

		private DataTable BindDataGrid(int nType)
		{
			SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
			DataTable dataTable = new DataTable();
			switch (nType)
			{
			case 1:
				dataTable.Columns.Add("风管规格", typeof(string));
				dataTable.Columns.Add("宽", typeof(int));
				dataTable.Columns.Add("高", typeof(int));
				using (List<DuctRectSize>.Enumerator enumerator = SqlLiteHelp.GetRectSize().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						DuctRectSize ductRectSize = enumerator.Current;
						dataTable.Rows.Add(new object[]
						{
							string.Format("{0:G}x{1:G}", ductRectSize.dWidth, ductRectSize.dHeight),
							(int)ductRectSize.dWidth,
							(int)ductRectSize.dHeight
						});
					}
					return dataTable;
				}
				break;
			case 2:
				break;
			case 3:
				goto IL_1BA;
			default:
				return dataTable;
			}
			dataTable.Columns.Add("圆形风管", typeof(string));
			dataTable.Columns.Add("直径", typeof(int));
			dataTable.Columns.Add(" ");
			using (List<double>.Enumerator enumerator2 = SqlLiteHelp.GetCircleSize().GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					double num = enumerator2.Current;
					dataTable.Rows.Add(new object[]
					{
						string.Format("D{0:G}", num),
						(int)num,
						""
					});
				}
				return dataTable;
			}
			IL_1BA:
			dataTable.Columns.Add("1");
			dataTable.Columns.Add("2");
			dataTable.Columns.Add("3");
			foreach (MaterialAndRough materialAndRough in SqlLiteHelp.GetMaterialAndRough())
			{
				dataTable.Rows.Add(new object[]
				{
					materialAndRough.strMaterial,
					materialAndRough.dRange.ToString(),
					materialAndRough.dSetValue.ToString()
				});
			}
			return dataTable;
		}

		private void AutoSort()
		{
			foreach (object obj in this.dvCCD.Columns)
			{
				((DataGridViewColumn)obj).SortMode = DataGridViewColumnSortMode.Automatic;
			}
			foreach (object obj2 in this.dvDuctSize.Columns)
			{
				((DataGridViewColumn)obj2).SortMode = DataGridViewColumnSortMode.Automatic;
			}
			foreach (object obj3 in this.dvCompute.Columns)
			{
				((DataGridViewColumn)obj3).SortMode = DataGridViewColumnSortMode.Automatic;
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (this.dvDuctSize[0, this.dvDuctSize.Rows.Count - 1].Value.ToString().Equals("新尺寸"))
			{
				YJKMessageBox.Show("请修改完毕后添加!");
				return;
			}
			DataTable dataTable = (DataTable)this.dvDuctSize.DataSource;
			DataRow dataRow = dataTable.NewRow();
			if (this.rbRect.Checked)
			{
				dataRow[0] = "新尺寸";
			}
			else
			{
				dataRow[0] = "新尺寸";
			}
			int count = dataTable.Rows.Count;
			dataTable.Rows.InsertAt(dataRow, count);
			this.dvDuctSize.FirstDisplayedScrollingRowIndex = this.dvDuctSize.Rows.Count - 1;
			this.blSize = true;
			this.dvDuctSize.Columns[0].ReadOnly = true;
		}

		private void dvDuctSize_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			if (this.blSize)
			{
				string value = this.dvDuctSize[0, this.dvDuctSize.Rows.Count - 1].Value.ToString();
				string text = this.dvDuctSize[1, this.dvDuctSize.Rows.Count - 1].Value.ToString();
				string text2 = this.dvDuctSize[2, this.dvDuctSize.Rows.Count - 1].Value.ToString();
				if (this.rbRect.Checked)
				{
					if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text2) || string.IsNullOrEmpty(value))
					{
						return;
					}
				}
				else if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(value))
				{
					return;
				}
				try
				{
					if (int.Parse(text) <= 0)
					{
						YJKMessageBox.Show("请输入大于0正整数!");
					}
					if (this.rbRect.Checked)
					{
						if (int.Parse(text2) <= 0)
						{
							YJKMessageBox.Show("请输入大于0正整数!");
						}
						string value2 = string.Format("{0}x{1}", text, text2);
						this.dvDuctSize[0, this.dvDuctSize.Rows.Count - 1].Value = value2;
					}
					else
					{
						string value3 = string.Format("D{0}", text);
						this.dvDuctSize[0, this.dvDuctSize.Rows.Count - 1].Value = value3;
					}
				}
				catch
				{
					YJKMessageBox.Show("风管尺寸输入非法，请重新修改!");
					return;
				}
				SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
				int dWidth = 0;
				int dHeight = 0;
				try
				{
					dWidth = int.Parse(text);
					if (this.rbRect.Checked)
					{
						dHeight = int.Parse(text2);
					}
				}
				catch
				{
					return;
				}
				if (this.rbRect.Checked && !string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && SqlLiteHelp.InsertDuctSize(dWidth, dHeight) == -1)
				{
					YJKMessageBox.Show("风管尺寸输入重复，请重新修改!");
					return;
				}
				if (!this.rbRect.Checked && !string.IsNullOrEmpty(text) && SqlLiteHelp.InsertDuctSize(dWidth, 0) == -1)
				{
					YJKMessageBox.Show("风管尺寸输入重复，请重新修改!");
					return;
				}
				this.blSize = false;
			}
		}

		private bool GetBoolDuctSize(string size)
		{
			for (int i = 0; i < this.dvDuctSize.Rows.Count; i++)
			{
				string text = this.dvDuctSize.Rows[i].Cells[0].GetText();
				if (size.Equals(text))
				{
					return true;
				}
			}
			return false;
		}

		private void btnAddCL_Click(object sender, EventArgs e)
		{
			string text = this.dvCCD[0, this.dvCCD.Rows.Count - 1].Value.ToString();
			string s = this.dvCCD[1, this.dvCCD.Rows.Count - 1].Value.ToString();
			string s2 = this.dvCCD[2, this.dvCCD.Rows.Count - 1].Value.ToString();
			try
			{
				if (text.Equals("新材料"))
				{
					YJKMessageBox.Show("请修改完毕后添加！");
					return;
				}
				double.Parse(s);
				double.Parse(s2);
			}
			catch
			{
				YJKMessageBox.Show("粗糙度设置不合法，请修改完毕后添加！");
				return;
			}
			DataTable dataTable = (DataTable)this.dvCCD.DataSource;
			DataRow dataRow = dataTable.NewRow();
			dataRow[0] = "新材料";
			dataRow[1] = "0.15";
			dataRow[2] = "0.15";
			int count = dataTable.Rows.Count;
			dataTable.Rows.InsertAt(dataRow, count);
			this.dvCCD.FirstDisplayedScrollingRowIndex = this.dvCCD.Rows.Count - 1;
			this.blMari = true;
		}

		private void dvCCD_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
			if (this.blMari)
			{
				string text = this.dvCCD[0, this.dvCCD.Rows.Count - 1].Value.ToString();
				string text2 = this.dvCCD[1, this.dvCCD.Rows.Count - 1].Value.ToString();
				string text3 = this.dvCCD[2, this.dvCCD.Rows.Count - 1].Value.ToString();
				try
				{
					if (string.IsNullOrEmpty(text2) || string.IsNullOrEmpty(text3))
					{
						return;
					}
					double.Parse(text2);
					double.Parse(text3);
				}
				catch
				{
					YJKMessageBox.Show("粗糙度设置不合法，请重新修改！");
					return;
				}
				if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text2) || string.IsNullOrEmpty(text3))
				{
					return;
				}
				if (SqlLiteHelp.AddMaterialAndRough(text, text2, text3) == -1)
				{
					YJKMessageBox.Show("材料名称重复，请重新修改！");
					return;
				}
				this.blMari = false;
				return;
			}
			else
			{
				SqlLiteHelp.UpdataDuctMaterial(this.dvCCD);
			}
		}

		private void btnDelete_Click(object sender, EventArgs e)
		{
			if (DialogResult.Yes == MessageBox.Show("是否删除选中的数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
			{
				if (this.dvDuctSize.Rows.Count == 1)
				{
					YJKMessageBox.Show("不能删除最后一行! ");
					return;
				}
				DataGridViewRow currentRow = this.dvDuctSize.CurrentRow;
				this.dvDuctSize[0, currentRow.Index].Value.ToString();
				string width = this.dvDuctSize[1, currentRow.Index].Value.ToString();
				string height = this.dvDuctSize[2, currentRow.Index].Value.ToString();
				SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
				if (this.rbRect.Checked)
				{
					SqlLiteHelp.DeleteDuctSize(width, height);
				}
				else
				{
					SqlLiteHelp.DeleteDuctSize(width, "");
				}
				this.dvDuctSize.Rows.Remove(currentRow);
			}
		}

		private void btnDeleteCL_Click(object sender, EventArgs e)
		{
			if (DialogResult.Yes == MessageBox.Show("是否删除选中的数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
			{
				if (this.dvCCD.Rows.Count == 1)
				{
					YJKMessageBox.Show("不能删除最后一行! ");
					return;
				}
				DataGridViewRow currentRow = this.dvCCD.CurrentRow;
				SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
				string strMaterial = this.dvCCD[0, currentRow.Index].Value.ToString();
				this.dvCCD[1, currentRow.Index].Value.ToString();
				this.dvCCD[2, currentRow.Index].Value.ToString();
				SqlLiteHelp.DeleteMaterialAndRough(strMaterial);
				this.dvCCD.Rows.Remove(currentRow);
			}
		}

		private void btnDeleteColor_Click(object sender, EventArgs e)
		{
			if (DialogResult.Yes == MessageBox.Show("是否删除选中的数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
			{
				if (this.dvCompute.Rows.Count == 1)
				{
					YJKMessageBox.Show("不能删除最后一行! ");
					return;
				}
				DataGridViewRow currentRow = this.dvCompute.CurrentRow;
				SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
				string s = this.dvCompute[0, currentRow.Index].Value.ToString();
				string s2 = this.dvCompute[1, currentRow.Index].Value.ToString();
				this.dvCompute[2, currentRow.Index].Value.ToString();
				double min = 0.0;
				double max = 0.0;
				try
				{
					min = double.Parse(s);
					max = double.Parse(s2);
				}
				catch
				{
					return;
				}
				if (this.rbSpeed.Checked)
				{
					SqlLiteHelp.DeleteTableData(1, min, max);
				}
				else
				{
					SqlLiteHelp.DeleteTableData(2, min, max);
				}
				this.dvCompute.Rows.Remove(currentRow);
			}
		}

		private void cbPress_TextChanged(object sender, EventArgs e)
		{
			try
			{
				double num = double.Parse(this.cbPress.Text);
				if (num < 0.0)
				{
					YJKMessageBox.Show("不能输入负值！");
				}
				if (num == 0.0)
				{
					YJKMessageBox.Show("只能输入大于0的正整数！");
					this.cbPress.Text = "101325";
				}
				else
				{
					this.ComputeInit();
				}
			}
			catch
			{
				YJKMessageBox.Show("非法数字，请重新输入！");
				this.cbPress.Text = "101325";
			}
		}

		private void cbTemp_TextChanged(object sender, EventArgs e)
		{
			try
			{
				if (this.cbTemp.Text.Equals("-"))
				{
					return;
				}
				double num = double.Parse(this.cbTemp.Text);
				if (this.cbTemp.Text.Contains("."))
				{
					double num2 = Math.Truncate(num * 10.0) / 10.0;
					if (num2 < num)
					{
						this.cbTemp.Text = num2.ToString();
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("非法数字，请重新输入！");
				this.cbTemp.Text = "20";
			}
			this.ComputeInit();
		}

		private void cbHumidity_TextChanged(object sender, EventArgs e)
		{
			try
			{
				double num = double.Parse(this.cbHumidity.Text);
				if (num > 100.0 || num < 1.0)
				{
					YJKMessageBox.Show("只能输入1-100的正整数！");
					this.cbHumidity.Text = "60";
				}
				else
				{
					this.ComputeInit();
				}
			}
			catch
			{
				YJKMessageBox.Show("非法数字，请重新输入！");
				this.cbHumidity.Text = "60";
			}
		}

		private void ComputeInit()
		{
			try
			{
				double num = double.Parse(this.cbTemp.Text);
				double num2 = double.Parse(this.cbHumidity.Text);
				double num3 = double.Parse(this.cbPress.Text);
				double num4 = 0.0;
				int num5 = (int)Math.Floor(num);
				int num6 = num5 + 40;
				if (num >= -40.0 && num <= 60.0)
				{
					if ((double)num5 < num)
					{
						num4 = BaseDuctClass.BaoHeYaLi[num6] + (BaseDuctClass.BaoHeYaLi[num6 + 1] - BaseDuctClass.BaoHeYaLi[num6]) / (num - (double)num5);
					}
					else if ((double)num5 == num)
					{
						num4 = BaseDuctClass.BaoHeYaLi[num6];
					}
					else
					{
						num4 = BaseDuctClass.BaoHeYaLi[num6 - 1] + (BaseDuctClass.BaoHeYaLi[num6] - BaseDuctClass.BaoHeYaLi[num6 - 1]) / ((double)num5 - num);
					}
				}
				double num7 = num2 / 100.0 * num4;
				double num8 = 0.003484 * (num3 / (273.15 + num)) - 0.00134 * (num7 / (273.15 + num));
				if (num < -40.0 || num > 60.0)
				{
					num8 = 352.0 / (num + 273.15);
				}
				double num9 = Math.Pow((273.15 + num) / 288.15, 1.5);
				double num10 = 398.54999999999995 / (273.15 + num + 110.4) * num9 * (1.7894 * Math.Pow(10.0, -5.0));
				this.tbMidu.Text = Math.Round(num8, 3).ToString();
				this.tbNiandu.Text = Math.Round(num10 * 1000000.0 / num8, 3).ToString();
			}
			catch
			{
			}
		}

		private void rbSpeed_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbSpeed.Checked)
			{
				this.BindDataGrid(1, true);
			}
		}

		private void rbRub_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbRub.Checked)
			{
				this.BindDataGrid(2, true);
			}
		}

		private void BindDataGrid(int Type, bool bl = true)
		{
			this.dvCompute.Rows.Clear();
			this.dvCompute.Columns.Clear();
			SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = ">最小流速";
			if (Type == 2)
			{
				dataGridViewTextBoxColumn.HeaderText = ">最小比摩阻";
			}
			dataGridViewTextBoxColumn.Width = 100;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvCompute.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn
			});
			dataGridViewTextBoxColumn.MinimumWidth = 100;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "<=最大流速";
			if (Type == 2)
			{
				dataGridViewTextBoxColumn2.HeaderText = ">最大比摩阻";
			}
			dataGridViewTextBoxColumn2.Width = 100;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvCompute.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn2
			});
			dataGridViewTextBoxColumn2.MinimumWidth = 100;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn3.HeaderText = "颜色";
			dataGridViewTextBoxColumn3.Width = 125;
			dataGridViewTextBoxColumn3.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvCompute.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn3
			});
			dataGridViewTextBoxColumn3.ReadOnly = true;
			dataGridViewTextBoxColumn3.MinimumWidth = 125;
			List<DuctCompute> compute = SqlLiteHelp.GetCompute(Type);
			for (int i = 0; i < compute.Count; i++)
			{
				string text = string.Concat(new string[]
				{
					"RGB ",
					compute[i].RGB[0].ToString(),
					" ",
					compute[i].RGB[1].ToString(),
					" ",
					compute[i].RGB[2].ToString()
				});
				object[] values = new object[]
				{
					compute[i].dMin,
					compute[i].dMax,
					text
				};
				this.dvCompute.Rows.Add(values);
				this.dvCompute[2, i].Value = "█" + text;
				this.dvCompute[2, i].Style.ForeColor = GetDuctPara.getXMLDataColor(text);
			}
		}

		private void dvCompute_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == 2 && e.RowIndex >= 0)
			{
				ColorDialog colorDialog = new ColorDialog();
				colorDialog.AllowFullOpen = true;
				colorDialog.FullOpen = true;
				System.Drawing.Color xmldataColor = GetDuctPara.getXMLDataColor(this.dvCompute[2, e.RowIndex].Value.ToString());
				if (!xmldataColor.IsKnownColor)
				{
					int[] array = new int[16];
					array[0] = GetDuctPara.GetIntAboutColor(xmldataColor);
					colorDialog.CustomColors = array;
				}
				colorDialog.Color = xmldataColor;
				DialogResult dialogResult = colorDialog.ShowDialog();
				if (DialogResult.OK == dialogResult)
				{
					string newRGB = GetDuctPara.getNewRGB(colorDialog.Color.R);
					string newRGB2 = GetDuctPara.getNewRGB(colorDialog.Color.G);
					string newRGB3 = GetDuctPara.getNewRGB(colorDialog.Color.B);
					string str = string.Concat(new string[]
					{
						"RGB ",
						newRGB.ToString(),
						" ",
						newRGB2.ToString(),
						" ",
						newRGB3.ToString()
					});
					this.dvCompute[2, e.RowIndex].Value = "█" + str;
					this.dvCompute[2, e.RowIndex].Style.ForeColor = colorDialog.Color;
					this.dvCompute[2, e.RowIndex].ReadOnly = true;
					string.Concat(new string[]
					{
						newRGB,
						",",
						newRGB2,
						",",
						newRGB3
					});
					double.Parse(this.dvCompute[0, e.RowIndex].Value.ToString());
					double.Parse(this.dvCompute[1, e.RowIndex].Value.ToString());
					SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
					if (this.rbSpeed.Checked)
					{
						this.lstSpeed.Clear();
						this.lstSpeed = this.GetDataSpeed();
						SqlLiteHelp.DeleteTableData("Duct_Compute", 1);
						using (List<DuctCompute>.Enumerator enumerator = this.lstSpeed.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								DuctCompute ductCompute = enumerator.Current;
								System.Drawing.Color xmldataColor2 = GetDuctPara.getXMLDataColor(ductCompute.strRGB);
								string strRGB = string.Format("{0:G},{1:G},{2:G}", xmldataColor2.R, xmldataColor2.G, xmldataColor2.B);
								SqlLiteHelp.AddSpeed(ductCompute.dMin, ductCompute.dMax, strRGB, 1);
							}
							return;
						}
					}
					this.lstMoca.Clear();
					this.lstMoca = this.GetDataSpeed();
					SqlLiteHelp.DeleteTableData("Duct_Compute", 2);
					foreach (DuctCompute ductCompute2 in this.lstMoca)
					{
						System.Drawing.Color xmldataColor3 = GetDuctPara.getXMLDataColor(ductCompute2.strRGB);
						string strRGB2 = string.Format("{0:G},{1:G},{2:G}", xmldataColor3.R, xmldataColor3.G, xmldataColor3.B);
						SqlLiteHelp.AddSpeed(ductCompute2.dMin, ductCompute2.dMax, strRGB2, 2);
					}
				}
			}
		}

		private void btnAddColor_Click(object sender, EventArgs e)
		{
			bool value = this.dvCompute[0, this.dvCompute.Rows.Count - 1].Value != null;
			object value2 = this.dvCompute[1, this.dvCompute.Rows.Count - 1].Value;
			if (!value || value2 == null)
			{
				YJKMessageBox.Show("请修改完毕后添加！");
				return;
			}
			string text = "█RGB 0 0 0";
			object[] values = new object[]
			{
				0,
				5,
				text
			};
			this.dvCompute.Rows.Add(values);
			this.dvCompute.FirstDisplayedScrollingRowIndex = this.dvCompute.Rows.Count - 1;
			this.blColor = true;
		}

		private void dvCompute_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
			if (this.blColor)
			{
				try
				{
					string text = this.dvCompute[0, this.dvCompute.Rows.Count - 1].Value.ToString();
					string text2 = this.dvCompute[1, this.dvCompute.Rows.Count - 1].Value.ToString();
					string text3 = this.dvCompute[2, this.dvCompute.Rows.Count - 1].Value.ToString();
					if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text2))
					{
						return;
					}
					System.Drawing.Color xmldataColor = GetDuctPara.getXMLDataColor(text3);
					double min = double.Parse(text);
					double max = double.Parse(text2);
					if ((text.Equals("0") && text2.Equals("0")) || string.IsNullOrEmpty(text3))
					{
						return;
					}
					string strRGB = string.Format("{0:G},{1:G},{2:G}", xmldataColor.R, xmldataColor.G, xmldataColor.B);
					if (this.rbSpeed.Checked)
					{
						if (SqlLiteHelp.AddSpeed(min, max, strRGB, 1) == -1)
						{
							YJKMessageBox.Show("数据重复，请修改后添加！");
							return;
						}
					}
					else if (SqlLiteHelp.AddSpeed(min, max, strRGB, 2) == -1)
					{
						YJKMessageBox.Show("数据重复，请修改后添加！");
						return;
					}
				}
				catch
				{
					return;
				}
				this.blColor = false;
				return;
			}
			if (this.rbSpeed.Checked)
			{
				SqlLiteHelp.UpdateDuctCompute(this.dvCompute, 1);
				return;
			}
			SqlLiteHelp.UpdateDuctCompute(this.dvCompute, 2);
		}

		private void BindGridSystemType(bool bl)
		{
			this.dvSystemSet.Rows.Clear();
			this.dvSystemSet.Columns.Clear();
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = "系统类型名称";
			dataGridViewTextBoxColumn.Width = 100;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn
			});
			dataGridViewTextBoxColumn.MinimumWidth = 100;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "缩写";
			dataGridViewTextBoxColumn2.Width = 60;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn2
			});
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn3.HeaderText = "线颜色";
			dataGridViewTextBoxColumn3.Width = 125;
			dataGridViewTextBoxColumn3.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn3
			});
			dataGridViewTextBoxColumn3.ReadOnly = true;
			dataGridViewTextBoxColumn3.MinimumWidth = 125;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn.HeaderText = "线型";
			dataGridViewComboBoxColumn.Width = 56;
			dataGridViewComboBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn
			});
			dataGridViewComboBoxColumn.FlatStyle = FlatStyle.Popup;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn2 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn2.HeaderText = "线宽";
			dataGridViewComboBoxColumn2.Width = 56;
			dataGridViewComboBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn2
			});
			dataGridViewComboBoxColumn2.FlatStyle = FlatStyle.Popup;
			foreach (LinePatternElement linePatternElement in GetDuctPara.Get_LinePatternElement(this.doc))
			{
				dataGridViewComboBoxColumn.Items.AddRange(new object[]
				{
					linePatternElement.Name
				});
			}
			dataGridViewComboBoxColumn.Items.Add("默认");
			for (int i = 1; i < 17; i++)
			{
				dataGridViewComboBoxColumn2.Items.Add(i.ToString());
			}
			dataGridViewComboBoxColumn2.Items.Add("默认");
			this.dvSystemSet.RowTemplate.Height = 22;
			this.dvSystemSet.RowHeadersWidth = 30;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn3 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn3.HeaderText = "系统分类";
			dataGridViewComboBoxColumn3.Width = 80;
			dataGridViewComboBoxColumn3.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn3
			});
			dataGridViewComboBoxColumn3.FlatStyle = FlatStyle.Popup;
			dataGridViewComboBoxColumn3.DefaultCellStyle.NullValue = "送风";
			List<string> list = new List<string>();
			foreach (MechanicalSystemType mechanicalSystemType in GetDuctPara.Get_MechanicalSystemType(this.doc))
			{
				string ductSystemTypeCH = AssistSystemType.GetDuctSystemTypeCH(mechanicalSystemType.SystemClassification.ToString());
				if (!list.Contains(ductSystemTypeCH))
				{
					dataGridViewComboBoxColumn3.Items.Add(ductSystemTypeCH);
					list.Add(ductSystemTypeCH);
				}
			}
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn4 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn4.HeaderText = "压力等级";
			dataGridViewComboBoxColumn4.Width = 80;
			dataGridViewComboBoxColumn4.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn4
			});
			dataGridViewComboBoxColumn4.FlatStyle = FlatStyle.Popup;
			dataGridViewComboBoxColumn4.Items.Add("中低压");
			dataGridViewComboBoxColumn4.Items.Add("高压");
			dataGridViewComboBoxColumn4.DefaultCellStyle.NullValue = "中低压";
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn5 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn5.HeaderText = "默认材质";
			dataGridViewComboBoxColumn5.Width = 80;
			dataGridViewComboBoxColumn5.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dvSystemSet.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn5
			});
			SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
			List<MaterialAndRough> materialAndRough = SqlLiteHelp.GetMaterialAndRough();
			foreach (MaterialAndRough materialAndRough2 in materialAndRough)
			{
				dataGridViewComboBoxColumn5.Items.Add(materialAndRough2.strMaterial);
			}
			dataGridViewComboBoxColumn5.FlatStyle = FlatStyle.Popup;
			dataGridViewComboBoxColumn5.DefaultCellStyle.NullValue = "镀锌钢板";
			if (bl)
			{
				using (List<systemTypeStruct>.Enumerator enumerator4 = GetDuctPara.GetCurrentSystemSetDat(this.doc).GetEnumerator())
				{
					while (enumerator4.MoveNext())
					{
						systemTypeStruct systemTypeStruct = enumerator4.Current;
						systemTypeStruct systemTypeStruct2 = new systemTypeStruct();
						systemTypeStruct2.PipingSystemType = systemTypeStruct.PipingSystemType;
						systemTypeStruct2.PipingSystemTypeAbb = systemTypeStruct.PipingSystemTypeAbb;
						systemTypeStruct2.PipeSystemType = systemTypeStruct.PipeSystemType;
						systemTypeStruct2.Color = systemTypeStruct.Color;
						systemTypeStruct2.LinePattern = systemTypeStruct.LinePattern;
						systemTypeStruct2.LineWeight = systemTypeStruct.LineWeight;
						systemTypeStruct2.SystemClass = systemTypeStruct.SystemClass;
						string ductSystemTypeCH2 = AssistSystemType.GetDuctSystemTypeCH(systemTypeStruct.PipeSystemType.ToString());
						List<string> paraDuctSystemType = SqlLiteHelp.GetParaDuctSystemType(systemTypeStruct.PipingSystemType, materialAndRough);
						object[] values = new object[]
						{
							systemTypeStruct.PipingSystemType,
							systemTypeStruct.PipingSystemTypeAbb,
							systemTypeStruct.Color,
							systemTypeStruct.LinePattern,
							systemTypeStruct.LineWeight,
							ductSystemTypeCH2,
							paraDuctSystemType[0],
							paraDuctSystemType[1]
						};
						this.dvSystemSet.Rows.Add(values);
					}
					goto IL_6A2;
				}
			}
			int selectedIndex = this.cbType.SelectedIndex;
			if (selectedIndex < 0)
			{
				YJKMessageBox.Show("数据不存在！");
				return;
			}
			foreach (DuctSytemSet ductSytemSet in this.lstDU[selectedIndex].lstSet)
			{
				string text = ductSytemSet.strLineType;
				if (string.IsNullOrEmpty(text))
				{
					text = "默认";
				}
				string text2 = "";
				foreach (MaterialAndRough materialAndRough3 in materialAndRough)
				{
					if (materialAndRough3.strMaterial == ductSytemSet.strMateria)
					{
						text2 = materialAndRough3.strMaterial;
						break;
					}
				}
				if (string.IsNullOrEmpty(text2))
				{
					text2 = materialAndRough[0].strMaterial;
				}
				object[] values2 = new object[]
				{
					ductSytemSet.strSystemName,
					ductSytemSet.strSystemTypeAbb,
					ductSytemSet.strLineColor,
					text,
					ductSytemSet.strLineWidth,
					ductSytemSet.strSystemType,
					ductSytemSet.strPresslevel,
					text2
				};
				this.dvSystemSet.Rows.Add(values2);
			}
			IL_6A2:
			this.ColorInint();
		}

		private void FormDuctSet_Load(object sender, EventArgs e)
		{
			DataTable dataSource = this.BindDataGrid(1);
			this.dvDuctSize.DataSource = null;
			this.dvDuctSize.DataSource = dataSource;
			this.dvDuctSize.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dvDuctSize.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			this.lstRectSize.Clear();
			this.lstRectSize = this.GetDataViewSize();
			DataTable dataSource2 = this.BindDataGrid(3);
			this.dvCCD.DataSource = null;
			this.dvCCD.DataSource = dataSource2;
			this.dvCCD.ColumnHeadersHeight = 40;
			this.dvCCD.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			this.dvCCD.MergeColumnNames.Add("Column1");
			this.dvCCD.AddSpanHeader(1, 2, "粗糙度K mm");
			this.lstMaterial.Clear();
			this.lstMaterial = this.GetDataMaterial();
			this.AutoSort();
			this.cbPress.SelectedIndex = 0;
			for (int i = -40; i < 61; i++)
			{
				this.cbTemp.Items.Add(i.ToString());
			}
			this.cbTemp.SelectedIndex = 60;
			this.cbHumidity.SelectedIndex = 0;
			this.GetUserData();
			this.rbSpeed.Checked = true;
			this.dvCompute.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dvCompute.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			this.lstSpeed.Clear();
			this.lstSpeed = this.GetDataSpeed();
			this.BindDataGrid(1, false);
			this.InitCbType();
			if (this.nInner == 0)
			{
				this.rbCurrent.Checked = true;
				this.BindGridSystemType(true);
			}
			else
			{
				this.rbInner.Checked = true;
				this.cbType.SelectedIndex = this.nTypeSelect;
				this.BindGridSystemType(false);
			}
			this.lstCurrent.Clear();
			this.lstCurrent = this.GetDataView();
		}

		private void ColorInint()
		{
			int count = this.dvSystemSet.Rows.Count;
			for (int i = 0; i < count; i++)
			{
				if (this.dvSystemSet[2, i].Value != null)
				{
					System.Drawing.Color xmldataColor = GetDuctPara.getXMLDataColor(this.dvSystemSet[2, i].Value.ToString());
					this.dvSystemSet[2, i].Style.ForeColor = xmldataColor;
					this.dvSystemSet[2, i].ReadOnly = true;
				}
			}
		}

		private void dvSystemSet_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == 2 && e.RowIndex >= 0)
			{
				ColorDialog colorDialog = new ColorDialog();
				colorDialog.AllowFullOpen = true;
				colorDialog.FullOpen = true;
				System.Drawing.Color xmldataColor = GetDuctPara.getXMLDataColor(this.dvSystemSet[2, e.RowIndex].Value.ToString());
				if (!xmldataColor.IsKnownColor)
				{
					int[] array = new int[16];
					array[0] = GetDuctPara.GetIntAboutColor(xmldataColor);
					colorDialog.CustomColors = array;
				}
				colorDialog.Color = xmldataColor;
				DialogResult dialogResult = colorDialog.ShowDialog();
				if (DialogResult.OK == dialogResult)
				{
					string newRGB = GetDuctPara.getNewRGB(colorDialog.Color.R);
					string newRGB2 = GetDuctPara.getNewRGB(colorDialog.Color.G);
					string newRGB3 = GetDuctPara.getNewRGB(colorDialog.Color.B);
					string str = string.Concat(new string[]
					{
						"RGB ",
						newRGB.ToString(),
						" ",
						newRGB2.ToString(),
						" ",
						newRGB3.ToString()
					});
					this.dvSystemSet[2, e.RowIndex].Value = "█" + str;
					this.dvSystemSet[2, e.RowIndex].Style.ForeColor = colorDialog.Color;
					this.dvSystemSet[2, e.RowIndex].ReadOnly = true;
					if (this.rbCurrent.Checked)
					{
						this.lstCurrent.Clear();
						this.lstCurrent = this.GetDataView();
					}
					if (this.rbInner.Checked)
					{
						int selectedIndex = this.cbType.SelectedIndex;
						this.lstDU[selectedIndex].lstSet.Clear();
						this.lstDU[selectedIndex].lstSet = this.GetDataView();
					}
				}
			}
		}

		private string RemoveNumber(string key)
		{
			return Regex.Replace(key, "\\d", "");
		}

		private void btnAddType_Click(object sender, EventArgs e)
		{
			int num = 1;
			string key = this.dvSystemSet[0, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string key2 = this.dvSystemSet[1, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string text = this.RemoveNumber(key);
			string str = this.RemoveNumber(key2);
			List<string> list = new List<string>();
			for (int i = 0; i < this.dvSystemSet.Rows.Count; i++)
			{
				string text2 = this.dvSystemSet[0, i].FormattedValue.ToString();
				if (text2.Contains(text))
				{
					string text3 = Regex.Replace(text2, "[^0-9]+", "");
					if (!string.IsNullOrEmpty(text3))
					{
						list.Add(text3);
					}
				}
			}
			if (list.Count != 0)
			{
				try
				{
					list.Sort();
					num = int.Parse(list.Last<string>()) + 1;
				}
				catch
				{
					num = 1;
				}
			}
			string value = text + num.ToString();
			string value2 = str + num.ToString();
			string text4 = this.dvSystemSet[2, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string value3 = this.dvSystemSet[3, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string value4 = this.dvSystemSet[4, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string value5 = this.dvSystemSet[5, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string value6 = this.dvSystemSet[6, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			string value7 = this.dvSystemSet[7, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			for (int j = 0; j < this.dvSystemSet.Rows.Count; j++)
			{
				if (this.dvSystemSet[0, j].FormattedValue.ToString().Equals(value))
				{
					YJKMessageBox.Show("已经存在该系统，请修改后添加！");
					return;
				}
			}
			this.dvSystemSet.Rows.Add(1);
			System.Drawing.Color xmldataColor = GetDuctPara.getXMLDataColor(text4);
			this.dvSystemSet[0, this.dvSystemSet.Rows.Count - 1].Value = value;
			this.dvSystemSet[1, this.dvSystemSet.Rows.Count - 1].Value = value2;
			this.dvSystemSet[2, this.dvSystemSet.Rows.Count - 1].Value = text4;
			this.dvSystemSet[2, this.dvSystemSet.Rows.Count - 1].Style.ForeColor = xmldataColor;
			this.dvSystemSet[2, this.dvSystemSet.Rows.Count - 1].ReadOnly = true;
			this.dvSystemSet.FirstDisplayedScrollingRowIndex = this.dvSystemSet.Rows.Count - 1;
			this.dvSystemSet[3, this.dvSystemSet.Rows.Count - 1].Value = value3;
			this.dvSystemSet[4, this.dvSystemSet.Rows.Count - 1].Value = value4;
			this.dvSystemSet[5, this.dvSystemSet.Rows.Count - 1].Value = value5;
			this.dvSystemSet[6, this.dvSystemSet.Rows.Count - 1].Value = value6;
			this.dvSystemSet[7, this.dvSystemSet.Rows.Count - 1].Value = value7;
			this.blAddType = true;
		}

		private void btnDelType_Click(object sender, EventArgs e)
		{
			new List<string>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			for (int i = 0; i < this.dvSystemSet.Rows.Count; i++)
			{
				string text = this.dvSystemSet[5, i].FormattedValue.ToString();
				if (text.Equals("送风"))
				{
					num++;
				}
				if (text.Equals("回风"))
				{
					num3++;
				}
				if (text.Equals("排风"))
				{
					num2++;
				}
			}
			string text2 = this.dvSystemSet[5, this.dvSystemSet.CurrentRow.Index].FormattedValue.ToString();
			if ((num == 1 && text2.Equals("送风")) || (text2.Equals("排风") && num2 == 1) || (text2.Equals("回风") && num3 == 1))
			{
				MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			if (DialogResult.Yes == MessageBox.Show("是否删除选中的数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
			{
				DataGridViewRow currentRow = this.dvSystemSet.CurrentRow;
				string text3 = currentRow.Cells[0].GetText();
				if (GetDuctPara.GetBoolSystemType(this.doc, text3))
				{
					MessageBox.Show("该系统类型正在被使用,不能删除！", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
				this.dvSystemSet.Rows.Remove(currentRow);
				int index = this.dvSystemSet.CurrentRow.Index;
				if (this.rbCurrent.Checked)
				{
					if (index >= this.lstCurrent.Count)
					{
						return;
					}
					this.lstCurrent.RemoveAt(index);
					Transaction transaction = new Transaction(this.doc, "del");
					transaction.Start();
					try
					{
						foreach (MechanicalSystemType mechanicalSystemType in GetDuctPara.Get_MechanicalSystemType(this.doc))
						{
							if (mechanicalSystemType.Name == text3)
							{
								this.doc.Delete(mechanicalSystemType.Id);
								break;
							}
						}
						transaction.Commit();
						return;
					}
					catch (Exception)
					{
						transaction.RollBack();
						return;
					}
				}
				int selectedIndex = this.cbType.SelectedIndex;
				this.lstDU[selectedIndex].lstSet.Clear();
				this.lstDU[selectedIndex].lstSet = this.GetDataView();
			}
		}

		private void rbInner_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbInner.Checked)
			{
				this.btnCreateModel.Enabled = true;
				this.btnDelModel.Enabled = true;
				this.btnInModel.Enabled = true;
				this.cbType.Enabled = true;
				this.BindGridSystemType(false);
			}
		}

		private void rbCurrent_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbCurrent.Checked)
			{
				this.btnCreateModel.Enabled = false;
				this.btnDelModel.Enabled = false;
				this.btnInModel.Enabled = false;
				this.cbType.Enabled = false;
				this.BindGridSystemType(true);
			}
		}

		private void cbType_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.BindGridSystemType(false);
		}

		private void btnDelModel_Click(object sender, EventArgs e)
		{
			if (this.cbType.Text.Equals("盈建科系统"))
			{
				YJKMessageBox.Show("盈建科系统不能删除！");
				return;
			}
			if (this.cbType.Items.Count > 0)
			{
				this.lstDU.RemoveAt(this.cbType.SelectedIndex);
				this.cbType.Items.RemoveAt(this.cbType.SelectedIndex);
				if (this.cbType.Items.Count > 0)
				{
					this.cbType.SelectedIndex = 0;
					return;
				}
				this.rbCurrent.Checked = true;
			}
		}

		private void btnInModel_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.InitialDirectory = "c:\\";
			openFileDialog.Filter = "Xml文件|*.xml|所有文件|*.*";
			openFileDialog.RestoreDirectory = true;
			openFileDialog.FilterIndex = 1;
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				string text = openFileDialog.FileNames[0];
				List<DuctSystemList> list = new XmlHelp().ReadSystemSet(text);
				this.lstDU.AddRange(list);
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
				foreach (DuctSystemList ductSystemList in list)
				{
					this.cbType.Items.Add(string.Concat(new string[]
					{
						fileNameWithoutExtension,
						"-",
						ductSystemList.strTypeName,
						"-",
						ductSystemList.strId
					}));
				}
				this.cbType.SelectedIndex = this.lstDU.Count - 1;
			}
		}

		private List<MaterialAndRough> GetDataMaterial()
		{
			List<MaterialAndRough> list = new List<MaterialAndRough>();
			for (int i = 0; i < this.dvCCD.Rows.Count; i++)
			{
				list.Add(new MaterialAndRough
				{
					strMaterial = this.dvCCD[0, i].Value.ToString(),
					dRange = double.Parse(this.dvCCD[1, i].Value.ToString()),
					dSetValue = double.Parse(this.dvCCD[2, i].Value.ToString())
				});
			}
			return list;
		}

		private List<DuctCompute> GetDataSpeed()
		{
			List<DuctCompute> list = new List<DuctCompute>();
			for (int i = 0; i < this.dvCompute.Rows.Count; i++)
			{
				list.Add(new DuctCompute
				{
					dMin = double.Parse(this.dvCompute[0, i].Value.ToString()),
					dMax = double.Parse(this.dvCompute[1, i].Value.ToString()),
					strRGB = this.dvCompute[2, i].Value.ToString()
				});
			}
			return list;
		}

		private List<DuctSytemSet> GetDataView()
		{
			List<DuctSytemSet> list = new List<DuctSytemSet>();
			try
			{
				for (int i = 0; i < this.dvSystemSet.RowCount; i++)
				{
					list.Add(new DuctSytemSet
					{
						strSystemName = this.dvSystemSet[0, i].Value.ToString(),
						strSystemTypeAbb = this.dvSystemSet[1, i].Value.ToString(),
						strLineColor = this.dvSystemSet[2, i].Value.ToString(),
						strLineType = this.dvSystemSet[3, i].Value.ToString(),
						strLineWidth = this.dvSystemSet[4, i].Value.ToString(),
						strSystemType = this.dvSystemSet[5, i].FormattedValue.ToString(),
						strPresslevel = this.dvSystemSet[6, i].FormattedValue.ToString(),
						strMateria = this.dvSystemSet[7, i].FormattedValue.ToString()
					});
				}
			}
			catch
			{
				return null;
			}
			return list;
		}

		private List<DuctRectSize> GetDataViewSize()
		{
			List<DuctRectSize> list = new List<DuctRectSize>();
			int i = 0;
			while (i < this.dvDuctSize.RowCount)
			{
				DuctRectSize ductRectSize = new DuctRectSize();
				if (this.rbRect.Checked)
				{
					try
					{
						ductRectSize.dWidth = double.Parse(this.dvDuctSize[1, i].Value.ToString());
						ductRectSize.dHeight = double.Parse(this.dvDuctSize[2, i].Value.ToString());
						goto IL_A0;
					}
					catch
					{
						goto IL_A7;
					}
					goto IL_69;
				}
				goto IL_69;
				IL_A7:
				i++;
				continue;
				IL_69:
				try
				{
					ductRectSize.dWidth = double.Parse(this.dvDuctSize[1, i].Value.ToString());
					ductRectSize.dHeight = 0.0;
				}
				catch
				{
					goto IL_A7;
				}
				IL_A0:
				list.Add(ductRectSize);
				goto IL_A7;
			}
			return list;
		}

		private void btnOutModel_Click(object sender, EventArgs e)
		{
			this.saveFileDialog1.Filter = "txt files (*.xml)|*.xml|All files (*.*)|*.*";
			this.saveFileDialog1.RestoreDirectory = true;
			if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
			{
				string fileName = this.saveFileDialog1.FileName;
				if (File.Exists(fileName))
				{
					File.Delete(fileName);
				}
				XmlHelp xmlHelp = new XmlHelp();
				if (this.rbInner.Checked)
				{
					xmlHelp.WriteXml(fileName, this.cbType.Text, "1", this.lstDU[this.cbType.SelectedIndex].lstSet);
				}
				else
				{
					xmlHelp.WriteXml(fileName, "当前系统样式", "1", this.GetDataView());
				}
				YJKMessageBox.Show("导出成功\n\r导入路径为:" + fileName);
			}
		}

		private void UpdateDB(List<DuctSytemSet> lstTemp)
		{
			try
			{
				SqlLiteHelp.SqlLiteDatabase(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
				SqlLiteHelp.UpdateDuctParam(new DuctParam
				{
					dPress = double.Parse(this.cbPress.Text),
					dTemperature = double.Parse(this.cbTemp.Text),
					dHumidity = double.Parse(this.cbHumidity.Text),
					dDensity = double.Parse(this.tbMidu.Text),
					dViscosity = double.Parse(this.tbNiandu.Text)
				});
				SqlLiteHelp.InsertDuctSystemType(lstTemp);
			}
			catch
			{
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			Transaction transaction = new Transaction(this.doc, "Update");
			try
			{
				transaction.Start();
				if (this.blAddType)
				{
					this.blAddType = false;
					bool value = this.dvSystemSet[1, this.dvSystemSet.Rows.Count - 1].Value != null;
					object value2 = this.dvSystemSet[2, this.dvSystemSet.Rows.Count - 1].Value;
					object value3 = this.dvSystemSet[3, this.dvSystemSet.Rows.Count - 1].Value;
					object value4 = this.dvSystemSet[4, this.dvSystemSet.Rows.Count - 1].Value;
					if (!value || value2 == null || value3 == null || value4 == null)
					{
						YJKMessageBox.Show("表格中不能存在空值!");
						transaction.RollBack();
						return;
					}
				}
				List<DuctSytemSet> dataView = this.GetDataView();
				if (dataView == null)
				{
					YJKMessageBox.Show("表格中不能存在空值!");
					transaction.RollBack();
					return;
				}
				if (this.GetBoolChongfu(dataView))
				{
					YJKMessageBox.Show("表格中存在重复系统名称!");
					transaction.RollBack();
					return;
				}
				if (this.rbCurrent.Checked)
				{
					this.lstCurrent.Clear();
					this.lstCurrent = dataView;
				}
				if (this.rbInner.Checked)
				{
					int selectedIndex = this.cbType.SelectedIndex;
					this.lstDU[selectedIndex].lstSet.Clear();
					this.lstDU[selectedIndex].lstSet = dataView;
				}
				if (this.rbCurrent.Checked)
				{
					this.nInner = 0;
					this.UpdateSystemDuctType(this.doc, this.lstCurrent);
				}
				else
				{
					this.nInner = 1;
					this.nTypeSelect = this.cbType.SelectedIndex;
					List<string> list = new List<string>();
					foreach (object item in this.cbType.Items)
					{
						list.Add(this.cbType.GetItemText(item));
					}
					XmlHelp xmlHelp = new XmlHelp();
					xmlHelp.ReadSystemSet("");
					xmlHelp.WriteXml(list, this.lstDU);
					int selectedIndex2 = this.cbType.SelectedIndex;
					List<DuctSytemSet> lstSet = this.lstDU[selectedIndex2].lstSet;
					this.lstCurrentOut = lstSet;
				}
				this.lstRectSize = this.GetDataViewSize();
				this.lstCriSize = this.GetDataViewSize();
				this.SetUserData();
				transaction.Commit();
				this.UpdateDB(dataView);
			}
			catch (Exception ex)
			{
				if (ex.ToString().Contains("Starting a new transaction is not permitted"))
				{
					transaction.Dispose();
					YJKMessageBox.Show("风管正在绘制，请修改参数后再绘制！");
					base.DialogResult = DialogResult.OK;
					base.Close();
					return;
				}
				transaction.RollBack();
			}
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void SetUserData()
		{
			string[] texts = new string[]
			{
				this.cbPress.Text,
				this.cbTemp.Text,
				this.cbHumidity.Text
			};
			this.hisHelp.WriteFormDuctSetText(texts);
		}

		private void GetUserData()
		{
			string[] formDuctSetText = this.hisHelp.GetFormDuctSetText();
			if (formDuctSetText[0] != "")
			{
				this.AddComboboxItems(this.cbPress, formDuctSetText[0]);
				this.cbPress.Text = formDuctSetText[0];
			}
			if (formDuctSetText[1] != "")
			{
				this.AddComboboxItems(this.cbTemp, formDuctSetText[1]);
				this.cbTemp.Text = formDuctSetText[1];
			}
			if (formDuctSetText[2] != "")
			{
				this.AddComboboxItems(this.cbHumidity, formDuctSetText[2]);
				this.cbHumidity.Text = formDuctSetText[2];
			}
		}

		private void AddComboboxItems(System.Windows.Forms.ComboBox cmb, string value)
		{
			if (!cmb.Items.Contains(value))
			{
				cmb.Items.Add(value);
			}
		}

		private bool GetBoolChongfu(List<DuctSytemSet> lstTemp)
		{
			return (from l in lstTemp
			group l by l.strSystemName into g
			where g.Count<DuctSytemSet>() > 1
			select g).Count<IGrouping<string, DuctSytemSet>>() > 0;
		}

		private void UpdateSystemDuctType(Autodesk.Revit.DB.Document doc, List<DuctSytemSet> lst)
		{
			List<MechanicalSystemType> list = GetDuctPara.Get_MechanicalSystemType(doc);
			List<ElementId> list2 = new List<ElementId>();
			int num = 0;
			using (List<DuctSytemSet>.Enumerator enumerator = lst.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					DuctSytemSet item = enumerator.Current;
					if ((from r in list
					where r.Name == item.strSystemName
					select r).Count<MechanicalSystemType>() == 0)
					{
						MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetDuctSystemTypeUS(item.strSystemType), true);
						MechanicalSystemType mechanicalSystemType = MechanicalSystemType.Create(doc, mepsystemClassification, item.strSystemName);
						mechanicalSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(item.strSystemTypeAbb);
						this.NewDrawDuct(mechanicalSystemType, item);
					}
					else
					{
						ElementId elementId = this.DrawDuct(num, item, list);
						if (elementId != null)
						{
							list2.Add(elementId);
						}
					}
					num++;
				}
			}
			foreach (ElementId elementId2 in list2)
			{
				try
				{
					doc.Delete(elementId2);
				}
				catch
				{
				}
			}
		}

		public void UpdateSystemDuctType(Autodesk.Revit.DB.Document doc, DuctSytemSet item, int i, ref bool blTishi)
		{
			SubTransaction subTransaction = new SubTransaction(doc);
			try
			{
				subTransaction.Start();
				List<MechanicalSystemType> list = GetDuctPara.Get_MechanicalSystemType(doc);
				List<ElementId> list2 = new List<ElementId>();
				if ((from r in list
				where r.Name == item.strSystemName
				select r).Count<MechanicalSystemType>() == 0)
				{
					MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetDuctSystemTypeUS(item.strSystemType), true);
					MechanicalSystemType mechanicalSystemType = MechanicalSystemType.Create(doc, mepsystemClassification, item.strSystemName);
					mechanicalSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(item.strSystemTypeAbb);
					this.NewDrawDuct(mechanicalSystemType, item);
				}
				else
				{
					if (blTishi)
					{
						FormMessageBox formMessageBox = new FormMessageBox("您选择的内置系统与当前项目中系统名称冲\r\n突,将替换为内置系统中设置。");
						if (formMessageBox.ShowDialog() == DialogResult.Cancel)
						{
							subTransaction.RollBack();
							return;
						}
						blTishi = formMessageBox.tishi;
					}
					ElementId elementId = this.DrawDuct(i, item, list);
					if (elementId != null)
					{
						list2.Add(elementId);
					}
				}
				foreach (ElementId elementId2 in list2)
				{
					try
					{
						doc.Delete(elementId2);
					}
					catch
					{
					}
				}
				subTransaction.Commit();
			}
			catch
			{
				subTransaction.RollBack();
			}
		}

		private ElementId DrawDuct(int i, DuctSytemSet set, List<MechanicalSystemType> listMechanicalSystemType)
		{
			ElementId result = null;
			for (int j = 0; j < listMechanicalSystemType.Count; j++)
			{
				if (listMechanicalSystemType[j].Name == set.strSystemName)
				{
					i = j;
					break;
				}
			}
			listMechanicalSystemType[i].Name = set.strSystemName;
			listMechanicalSystemType[i].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(set.strSystemTypeAbb);
			string ductSystemTypeCH = AssistSystemType.GetDuctSystemTypeCH(listMechanicalSystemType[i].SystemClassification.ToString());
			if (set.strSystemType != ductSystemTypeCH)
			{
				if (GetDuctPara.GetBoolSystemType(this.doc, listMechanicalSystemType[i].Name))
				{
					return result;
				}
				try
				{
					result = listMechanicalSystemType[i].Id;
					MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetDuctSystemTypeUS(set.strSystemType), true);
					MechanicalSystemType mechanicalSystemType = MechanicalSystemType.Create(this.doc, mepsystemClassification, set.strSystemName);
					mechanicalSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(set.strSystemTypeAbb);
					this.NewDrawDuct(mechanicalSystemType, set);
					return result;
				}
				catch
				{
					return result;
				}
			}
			if (set.strLineType != null && set.strLineType != "默认")
			{
				listMechanicalSystemType[i].LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, set.strLineType).Id;
			}
			else
			{
				listMechanicalSystemType[i].LinePatternId = ElementId.InvalidElementId;
			}
			if (set.strLineWidth != "默认")
			{
				listMechanicalSystemType[i].LineWeight = int.Parse(set.strLineWidth);
			}
			else
			{
				listMechanicalSystemType[i].LineWeight = 5;
			}
			if (set.strLineColor != "默认")
			{
                Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(set.strLineColor);
				listMechanicalSystemType[i].LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(listMechanicalSystemType[i], this.doc, revirColor, false, listMechanicalSystemType[i].LinePatternId, listMechanicalSystemType[i].LineWeight, false);
			}
			return result;
		}

		private void NewDrawDuct(MechanicalSystemType mst, DuctSytemSet set)
		{
			if (set.strLineType != null && set.strLineType != "默认")
			{
				mst.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, set.strLineType).Id;
			}
			else
			{
				mst.LinePatternId = ElementId.InvalidElementId;
			}
			if (set.strLineWidth != "默认")
			{
				mst.LineWeight = int.Parse(set.strLineWidth);
			}
			else
			{
				mst.LineWeight = 5;
			}
			if (set.strLineColor != "默认")
			{
                Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(set.strLineColor);
				mst.LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(mst, this.doc, revirColor, false, mst.LinePatternId, mst.LineWeight, false);
			}
		}

		private void cbPress_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '-' && this.cbPress.Text != "")
			{
				MessageBox.Show("不能输入负数");
				this.cbPress.SelectedIndex = 0;
				e.Handled = true;
			}
		}

		private void cbHumidity_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '-' && this.cbHumidity.Text != "")
			{
				MessageBox.Show("不能输入负数");
				this.cbHumidity.SelectedIndex = 0;
				e.Handled = true;
			}
		}

		private void dvDuctSize_MouseLeave(object sender, EventArgs e)
		{
			this.dvDuctSize[0, this.dvDuctSize.Rows.Count - 1].Value.ToString();
			this.dvDuctSize[1, this.dvDuctSize.Rows.Count - 1].Value.ToString();
			this.dvDuctSize[2, this.dvDuctSize.Rows.Count - 1].Value.ToString();
		}

		private void FormDuctSet_FormClosing(object sender, FormClosingEventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void dvDuctSize_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
			YJKMessageBox.Show("请输入大于0的正整数！");
		}

		private UIApplication uiApp;

		private Document doc;

		public List<DuctSytemSet> lstCurrentOut = new List<DuctSytemSet>();

		private List<DuctSystemList> lstDU = new List<DuctSystemList>();

		private List<DuctSytemSet> lstCurrent = new List<DuctSytemSet>();

		private List<DuctRectSize> lstRectSize = new List<DuctRectSize>();

		private List<DuctRectSize> lstCriSize = new List<DuctRectSize>();

		private List<MaterialAndRough> lstMaterial = new List<MaterialAndRough>();

		private List<DuctCompute> lstSpeed = new List<DuctCompute>();

		private List<DuctCompute> lstMoca = new List<DuctCompute>();

		public DuctHisHelp hisHelp = new DuctHisHelp();

		public int nInner;

		public int nTypeSelect;

		private bool blSize;

		private bool blMari;

		private bool blColor;

		private bool blAddType;
	}
}
